// asserts/component/common/processLine/processLine.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    pTag: {
      type: String,
      value: ""
    },
    pHideTag: {
      type: Boolean,
      value: false
    },
    pActive: Number,
    pTotal: {
      type: Number,
      value: 100
    }, // 默认值

  },

  /**
   * 组件的初始数据
   */
  data: {
    rate: "0%",
    tag: ""
  },
  ready: function () {
    this.buidView();
  },
  methods: {
    updateProcess: function (inputA, inputT) {
      var total = 100;
      var active = 0;

      if(inputA == null && inputT== null){
        return;
      }

      if(inputT == null){
        inputT = this.properties.pTotal;
      }

      if (inputT > 0) {
        total = inputT;
      } else {
        console.warn("process total <= 0 !");
        this.data.rate = "0%";
        return;
      }

      if (inputA > 0) {
        active = inputA;
      }

      var rate= "";
      if (active >= total) {
        rate = "100%";
      }else{
        rate = (active * 100 - (active * 100 % total)) / total + "%";
      }

      var tag = this.properties.pTag;
      if (this.properties.pHideTag) {
        tag = "";
      } else {
        tag = rate;
      }

      this.setData({
        rate: rate,
        tag: tag
      })
    },
    buidView: function () {
      this.updateProcess(this.properties.pActive, this.properties.pTotal);
    },
  }
})